home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / threads / ThreadsMachDep.s < prev    next >
Text File  |  1991-12-04  |  6KB  |  275 lines

  1. /*
  2.  * ThreadsMachDep.s for SPARC processor
  3.  *
  4.  * Demers, January 25, 1991 4:21:32 pm PST
  5.  * Boehm, July 11, 1990 6:17:29 pm PDT
  6.  */
  7.  
  8. #include <sun4/trap.h>
  9. #include "xr/ThreadsInlines.h"
  10.  
  11. !
  12. !
  13. !    XR_Jump3(arg, proc, sp)
  14. !
  15. !    call `proc(arg)' with stack pointer initially set to `sp'.
  16. !
  17. !
  18. !    XR_Jump5(arg, proc, sp, opc, osp)
  19. !
  20. !    call `proc(arg)' with stack pointer initially set to `sp'.
  21. !    make frame look (to dbx) like caller was running on (opc, osp) context.
  22. !
  23.     .seg    "text"
  24.     .proc    16
  25.     .globl    _XR_Jump3
  26. _XR_Jump3:
  27.     t    ST_FLUSH_WINDOWS
  28.     mov    %sp,%fp        ! frame pointer
  29.     add    %o2,-96,%sp    ! new sp
  30.     clr    %i7
  31.     call    %o1
  32.     nop
  33.     t    ST_DIV0
  34. !
  35. !
  36.     .seg    "text"
  37.     .proc    16
  38.     .globl    _XR_Jump5
  39. _XR_Jump5:
  40.     t    ST_FLUSH_WINDOWS
  41.     mov    %o4,%fp        ! frame pointer
  42.     add    %o2,-96,%sp    ! new sp
  43.     mov    %o3,%i7        ! return pointer
  44.     call    %o1
  45.     nop
  46.     t    ST_DIV0
  47.  
  48. !
  49. !    old = XR_TestAndSet (ax)
  50. !    int * ax;
  51. !
  52. !    atomically test *ax and set it to non-0.
  53. !
  54. !    n.b. presupposes 0 == FALSE, non-0 == TRUE
  55. !
  56.     .seg    "text"
  57.     .proc    16
  58.     .globl    _XR_TestAndSet
  59. _XR_TestAndSet:
  60. !
  61. ! The followng obvious implementation fails if it has to be restarted (e.g.
  62. ! because of a write-protect fault caused by our garbage collector):
  63. !
  64. !    ldstub    [%o0],%o0
  65. !    retl
  66. !    nop
  67. !
  68. stb %g0,[%o0+3]   ! partially circumvent reputed ldstub bug
  69.     ldstub    [%o0],%g1
  70.     retl
  71.     mov    %g1,%o0        ! delay slot
  72.  
  73. !
  74. !    replacement for cerror
  75. !
  76. !    stores error value in p_errno field (displacement 0) of *XR_currThread
  77. !
  78.     .seg    "data"
  79.     .globl    _errno,_XR_currThread
  80.     .align    4
  81.  
  82. ! THE FOLLOWING DEFINES MUST AGREE WITH Threads.h
  83.  
  84. #define T_ERRNO_OFF    0
  85. #define T_ERRNOLOCK_OFF    4
  86. #define T_VPETORESCHEDONMONITOREXIT_OFF 8
  87. #define T_MLNEEDED_OFF    12
  88.  
  89. !
  90. ! _errno is now declared in per-processor state
  91. !
  92. ! _errno:
  93. !     .word    0
  94.  
  95.     .seg    "text"
  96.     .proc    16
  97.     .globl    cerror
  98. cerror:
  99. !   _errno := error number from %o0
  100.     sethi    %hi(_errno),%g1
  101.     st    %o0,[%g1+%lo(_errno)]
  102. !   %g1 := XR_currThread
  103.     sethi    %hi(_XR_currThread),%g1
  104.     ld    [%g1+%lo(_XR_currThread)],%g1
  105. !   if( %g1 == NIL ) goto out
  106.     tst    %g1
  107.     bz    out
  108.     nop
  109. !   %g1 := %g1->t_errnoLock
  110.     ld    [%g1+%lo(T_ERRNOLOCK_OFF)],%g1
  111. !   if( %g1 != 0 ) goto out
  112.     tst    %g1
  113.     bnz    out
  114. !   %g1 := XR_currThread
  115.     sethi    %hi(_XR_currThread),%g1        ! delay slot ok
  116.     ld    [%g1+%lo(_XR_currThread)],%g1
  117. !   %g1->t_errno := error number from %o0
  118.     st    %o0,[%g1+%lo(T_ERRNO_OFF)]
  119. out:
  120. !   return( -1 )
  121.     retl
  122.     mov     -1,%o0                ! delay slot
  123. !
  124. !
  125. ! Replacement for _setjmp / _longjmp
  126. !
  127. ! Doesn't do Sun's check-for-longjmp-0 hack.
  128. !
  129. ! This uses three cells of the jmp_buf:
  130. !
  131. !   buf[0] (offset=0): saved pc (exactly as stored by the call instruction)
  132. !   buf[1] (offset=4): not used
  133. !   buf[2] (offset=8): saved sp (stored here for compatibility with _setjmp)
  134. !
  135.     .seg    "text"
  136.     .proc    16
  137.     .globl    _XR_setjmp
  138. _XR_setjmp:
  139.     st    %sp,[%o0+8]
  140.     st    %o7,[%o0]
  141.     retl
  142.     clr    %o0        ! delay slot
  143. !
  144. !
  145.     .seg    "text"
  146.     .proc    16
  147.     .globl    _XR_longjmp
  148. _XR_longjmp:
  149.     t    ST_FLUSH_WINDOWS
  150.     sub    %sp,64,%sp    ! leave space for another copy of regs in case
  151.                 ! preempted while fp and sp inconsistent below.
  152.                 ! (this is why C library versions of _setjmp/
  153.                 ! _longjmp can't be used)
  154.     ld    [%o0+8],%fp
  155.     sub    %fp,64,%sp
  156.     ld    [%o0],%i7    ! return ptr
  157.     ret
  158.     restore    %o1,0,%o0    ! delay slot
  159.  
  160.  
  161. !
  162. !
  163. ! Flush SPARC register windows
  164. !
  165. !
  166.     .seg    "text"
  167.     .proc    16
  168.     .globl    _XR_FlushWindows
  169. _XR_FlushWindows:
  170.     t    ST_FLUSH_WINDOWS
  171.     retl
  172.     nop
  173. !
  174. !
  175. ! Accelerators for monitor entry and exit
  176. !
  177. !
  178.  
  179. #if (XR_MONITOR_ENTRY || XR_MONITOR_EXIT)
  180. ! THE FOLLOWING MUST BE CONSISTENT WITH typedef XR_ML in Threads.h
  181. #       define    ML_LOCK_OFF    0
  182. #       define     ML_WQTAIL_OFF    4
  183. #       define    ML_HOLDER_OFF    8
  184. #endif
  185.  
  186. #if XR_MONITOR_ENTRY
  187. !
  188. ! XR_MonitorEntry(ml)
  189. !
  190.  
  191.     .seg    "text"
  192.     .proc    16
  193.     .globl    _XR_MonitorEntry
  194.     .globl    _XR_MonitorEntryOutOfLine
  195.     .globl    _XR_currThread
  196.     .align    4
  197.  
  198. _XR_MonitorEntry:
  199. !   g1 := TestAndSet(ml->ml_wq.wq_gsl)
  200. ! stb %g0,[%o0+3]   ! circumvent reputed ldstub bug
  201.     ldstub    [%o0+ML_LOCK_OFF],%g1
  202. !   o1 := ml->ml_holder
  203.     ld    [%o0+ML_HOLDER_OFF],%o1
  204. !   o2 := XR_currThread
  205.     sethi    %hi(_XR_currThread),%o2
  206.     ld    [%o2+%lo(_XR_currThread)],%o2
  207. !   if( g1 != 0 ) goto MonEntryCall;
  208.     tst    %g1
  209.     bnz    MonEntryCall
  210. !   if( ml->ml_holder == NIL )
  211. !    { ml->ml_holder = XR_currThread; goto EasyMonEntry; }
  212.     tst    %o1            ! delay slot ok
  213.     bz,a    EasyMonEntry
  214.     st    %o2,[%o0+ML_HOLDER_OFF]
  215. MonEntryCallWithLock:
  216. !   Unset(ml->ml_wq.wq_gsl);
  217.     st    %g0,[%o0+ML_LOCK_OFF]
  218. MonEntryCall:
  219. !   transfer to XR_MonitorEntryOutOfLine
  220.     sethi    %hi(_XR_MonitorEntryOutOfLine),%g1
  221.     jmpl    %g1+%lo(_XR_MonitorEntryOutOfLine),%g0
  222.     nop
  223. EasyMonEntry:
  224. !   return; Unset(ml->ml_wq.wq_gsl)
  225.     retl
  226.     st    %g0,[%o0+ML_LOCK_OFF]    ! delay slot
  227. #endif
  228.  
  229. #if XR_MONITOR_EXIT
  230. !
  231. ! XR_MonitorExit(ml)
  232. !
  233.  
  234.     .seg    "text"
  235.     .proc    16
  236.     .globl    _XR_MonitorExit
  237.     .globl    _XR_MonitorExitOutOfLine
  238.     .align    4
  239.  
  240. _XR_MonitorExit:
  241. !   g1 := TestAndSet(ml->ml_wq.wq_gsl)
  242. ! stb %g0,[%o0+3]   ! circumvent reputed ldstub bug
  243.     ldstub    [%o0+ML_LOCK_OFF],%g1
  244. !   o1 := ml->ml_wq.wq_tail
  245.     ld    [%o0+ML_WQTAIL_OFF],%o1
  246. !   o2 := XR_currThread
  247.     sethi    %hi(_XR_currThread),%o2
  248.     ld    [%o2+%lo(_XR_currThread)],%o2
  249. !   if( g1 != 0 ) goto MonExitCall;
  250.     tst    %g1
  251.     bnz    MonExitCall
  252. !   o2 := XR_currThread->t_vpeToReschedOnMonitorExit;
  253.     ld    [%o2+T_VPETORESCHEDONMONITOREXIT_OFF],%o2    ! delay slot OK
  254. !   if( ml->ml_wq.wq_tail != NIL ) { goto MonExitCallWithLock; }
  255.     tst    %o1    ! delay slot OK
  256.     bnz    MonExitCallWithLock
  257. !   if( XR_currThread->t_vpeToReschedOnMonitorExit == NIL )
  258. !           { ml->ml_holder := NIL; goto EasyMonExit; }
  259.     tst    %o2    ! delay slot OK
  260.     bz,a    EasyMonExit
  261.     st    %g0,[%o0+ML_HOLDER_OFF]        ! annulled delay slot
  262. MonExitCallWithLock:
  263. !   release lock
  264.     st    %g0,[%o0+ML_LOCK_OFF]
  265. MonExitCall:
  266. !   transfer to XR_MonitorExitOutOfLine
  267.     sethi    %hi(_XR_MonitorExitOutOfLine),%g1
  268.     jmpl    %g1+%lo(_XR_MonitorExitOutOfLine),%g0
  269.     nop
  270. EasyMonExit:
  271. !   Unset(ml->ml_wq.wq_gsl); return
  272.     retl
  273.     st    %g0,[%o0+ML_LOCK_OFF]    ! delay slot
  274. #endif
  275.